package httpx

import (
	"strconv"
)

func humanSize(size int64) string {
	const (
		b float64 = 1 << (10 * iota)
		k
		m
		g
	)
	s := float64(size)
	switch {
	case s > g:
		return strconv.FormatFloat(s/g, 'f', 2, 64) + "G"
	case s > m:
		return strconv.FormatFloat(s/m, 'f', 2, 64) + "M"
	case s > k:
		return strconv.FormatFloat(s/k, 'f', 2, 64) + "K"
	default:
		return strconv.FormatInt(size, 10) + "B"
	}
}
